// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import "babel-polyfill"

import './assets/js/commonjs.js';
import './assets/css/common.css';

import store from './store';


import hljs from 'highlight.js' // 引入JS
import 'highlight.js/styles/googlecode.css' //样式文件

Vue.directive('highlight',function (el) {
  let blocks = el.querySelectorAll('pre code');
  blocks.forEach((block)=>{
    hljs.highlightBlock(block)
  })
})

Vue.config.productionTip = false
Vue.use(ElementUI)

import PortalUI from '../packages';
Vue.use(PortalUI);

import axios from 'axios';
Vue.prototype.$http = Vue.http = axios;

import global_ from './Global.vue'
Vue.prototype.GLOBAL = global_;
axios.defaults.baseURL=global_.BASE_URL;
Vue.prototype.$ajax = axios;

axios.interceptors.request.use(
  config => {
      if (store.state.auth.token) {  // 判断是否存在token，如果存在的话，则每个http header都加上token
          config.headers.auth = `${store.state.auth.token}`;
      }
      return config;
  },
  err => {
      return Promise.reject(err);
});


new Vue({
  el: '#app',
  router,
  store,
  components: { App },

  template: '<App/>'
})
